#include<stdio.h>
#include<fcntl.h>
#include<string.h>

int main()
{
  FILE* fp = fopen("temp.txt","w+");
  if(fp==NULL)
  {
    perror("fopen error");
    return -1;
  }

  char *data = "今天过年\n";
  size_t ret = fwrite(data,1,strlen(data),fp);
  if(ret!=strlen(data))
  {
    perror("fwrite error");
    fclose(fp);
    return -1;
  }
  //偏移到文件起始位置
  fseek(fp,0,SEEK_SET);

  char buf[1024]={0};
  ret = fread(buf,1,1023,fp);
  if(ret<0)
  {
    perror("fread error");
    fclose(fp);
    return -1;
  }
  printf("%s\n",buf);
  fclose(fp);
  return -1;
}
